//app.js
App({
  onLaunch: function () {
    var that = this;
    this.getUserInfo()
  },
  getUserInfo: function (cb) {
    var that = this
    if (this.globalData.userInfo) {
      typeof cb == "function" && cb(this.globalData.userInfo)
    } else {
      //调用登录接口
      wx.getUserInfo({
        withCredentials: false,
        success: function (res) {
          that.globalData.userInfo = res.userInfo;
          wx.login({
            success: function (res) {
              //调用request请求api转换登录凭证 
              wx.request({
                url: 'https://www.sxjtwq.com/api/index/getopenid?code=' + res.code + '&nick=' + that.globalData.userInfo.nickName + '&img=' + that.globalData.userInfo.avatarUrl,
                header: {
                  'content-type': 'json'
                },
                success: function (res) {
                  // if (res.data.success === true) {
                    var openId = res.data
                    that.globalData.openId = openId;
                    wx.setStorageSync('openId', openId)
                  // }
                }
              })
            }
          })
          typeof cb == "function" && cb(that.globalData.userInfo)
        },
        fail: res => {
          // wx.navigateTo({
          //   url: '/pages/login/login',
          // })
        }
      })
    }
  },
  globalData: {
    userInfo: null,
    appid:  'wx4698a53312c6d82e',
    url: 'https://www.sxjtwq.com/api/index/',//'https://www.wanxiangrl.com/api/index/',
    imgurl:'https://www.sxjtwq.com/Uploads/',
    payurl: 'https://www.sxjtwq.com/api/pay?',
    telurl:'https://www.sxjtwq.com/api/Tel/'
  }
})